/**
 * @description 模型入口
 * @author 印明帝
 */

const User = require('./User')
const Blog = require('./Blog')
const UserRelation = require('./UserRelation')
const AtRelation = require('./AtRelation')

// 外键设置，博客是属于用户表的，多对一关系
Blog.belongsTo(User, {
  foreignKey: 'userId',
})

// 外键设置，用户关系表外键
UserRelation.belongsTo(User,{
  foreignKey: 'followerId'
})
// 外键设置，用户关系表外键
User.hasMany(UserRelation, {
  foreignKey: 'userId'
})

// 设置外键blog关联到UserRelation
Blog.belongsTo(UserRelation, {
  foreignKey: 'userId',
  targetKey: 'followerId'
})

// 设置atRelation表的外键
Blog.hasMany(AtRelation, {
  foreignKey: 'blogId'
})

module.exports = {
  User,
  Blog,
  UserRelation,
  AtRelation
}